extends BattleState

@onready var monster_handler = $"../../MonsterHandler"

func _ready():
	Events.monster_action_completed.connect(_on_monster_action_completed)
	Events.monster_round_ended.connect(_monster_round_ended)
	
	
func enter() -> void:
	var m = monster_handler.get_children()[0]
	#monster 开始行动
	m.in_round()
	

func _on_monster_action_completed(enemy: Monster) -> void:
	var monster_groups = monster_handler.get_children()
	var index = monster_groups.find(enemy)
	if index == monster_groups.size() - 1:
		Events.monster_round_ended.emit()
		return
	var next_enemy: Monster = monster_groups[index + 1] as Monster
	CardManager.round_data.clear_died_monster.emit()
	next_enemy.in_round()


func _monster_round_ended():
	var monster_groups: Array = monster_handler.get_children()
	if monster_groups.size() != 0:
		for m in monster_groups:
			m.after_round()
			
	transition_requested.emit(self, State.STATE_BEFORE_NEW_ROUND)
